package com.testape2d;

import android.app.Activity;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager; 

public class Physics extends Activity {
    PhysicsWorld mWorld;
    private Handler mHandler;
//    private int gccount=0;
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	//info: http://developer.android.com/guide/developing/tools/traceview.html
    	// start tracing to "/sdcard/testape2d.trace"

        super.onCreate(null);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // this.requestWindowFeature(Window.FEATURE_NO_TITLE);
       
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
          
//        mWorld = new PhysicsWorld(this,dm.widthPixels,dm.heightPixels-100);
        mWorld = new PhysicsWorld(this,dm.widthPixels,dm.heightPixels);
        this.setContentView(this.mWorld);

        // Start Regular Update

        mHandler = new Handler();
        mHandler.post(update);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mHandler.removeCallbacks(update);
    }

    private Runnable update = new Runnable() {
        public void run() {
            mWorld.update();
//            mHandler.postDelayed(update, (long) (10/mWorld.timeStep));
//            mHandler.postDelayed(update, (long) (10/mWorld.timeStep));
            mHandler.postDelayed(update, 1);
 //           setTitle("creationCount="+Vec2.creationCount);
//            gccount++;
//            if ((gccount%3)==0)
//              System.gc();
/*            if (Vec2.creationCount>10000)
            {
            	Vec2.creationCount=0;
                System.gc();
            }
*/            
        }
    };

    @Override
    protected void onResume()
    {
         super.onResume();
    }
   
    @Override
    protected void onStop()
    {
         super.onStop();
         System.exit(0);
    }    
}